;------------------------------------------------------------
;App_name : DECODER.EXE
;Author : mrezzuz
;web site : http://www.1t.2t.3t.4t.com
;Date : 20/4/2003
;------------------------------------------------------------
Title decoder
.MODEL small
.STACK 100H
.DATA
LF EQU 0AH
CR EQU 0DH
MSG DB 1000H DUP (0) ;Encode up to 4 kbytes
HR db LF,CR,'----------------------------------------------$'
CODE_MSG db 'The code : $'
MSG_MSG db 'The message : $'
WELCOM DB CR,LF,'Type in a new message for working:',CR,LF,'$'
AGAIN DB CR,LF,'Play again ',1h,' ?[Y For agree]',LF,CR,'$'
CODE_VAL DB 9BH
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;---------------------------------
START:
XOR AX,AX
XOR BX,BX
XOR CX,CX
XOR DX,DX
LEA DX,HR
MOV AH,9
INT 21H
LEA DX,WELCOM ;print the welcom message
INT 21H
;start to read the user input
LEA BX,MSG
READ_BYTE :
MOV AH,1 ;input one char
INT 21H
CMP AL,CR ;compare end of user inputs
JE END_READ
CMP AL,08H ;compare backspace
JE BACK
MOV [BX],AL ;store input char into msg
INC CX ;increment counter
INC BX ;increment offset
JMP READ_BYTE
BACK:
MOV DL,32 ;Print space and backspace to clear the backed char.
MOV AH,2
INT 21H
MOV DL,8
INT 21H
DEC CX ;if backspace then dec counter and offset
DEC BX
JMP READ_BYTE
END_READ:
;Not operate until user input at least one char or
;Until cx > 00h and else ask for again
CMP CX,00H
JLE ask_again
CALL DEC_INC ;calls xor function TO ENCODE.
MOV AH,2 ;print new line
MOV DL,LF
INT 21H
MOV DL,CR
INT 21H
LEA DX,CODE_MSG
MOV AH,9
INT 21H
CALL PRINT_MSG ;calls msg printting which was stored in msg
CALL DEC_INC ;call xor TO DECODE .
LEA DX,MSG_MSG
MOV AH,9
INT 21H
CALL PRINT_MSG
ask_again:
LEA DX,AGAIN
MOV AH,9
INT 21H
MOV AH,1 ;scan what's user replay . if Y or y then again else exit
INT 21H
CMP AL,'Y'
JE START
CMP AL,'y'
JE START
END_MAIN: ;Exit to dos
MOV AH,4CH
INT 21H
MAIN ENDP
;___________________________________________________________________
PRINT_MSG PROC
;The procedure prints the bytes sequancly from the msg address CX times.
;CX must > 00h
;The procedure uses BX as an offset
PUSH CX ;store CX
MOV AH,2 ;print new line
MOV DL,LF
INT 21H
MOV DL,CR
INT 21H
LEA BX,MSG
START1:
MOV DL,[BX] ;start print first char of msg address
INC BX ;icrement the offset
INT 21H
LOOP START1
MOV AH,2 ;print new line
MOV DL,LF
INT 21H
MOV DL,CR
INT 21H
POP CX ;return CX
RET
PRINT_MSG ENDP
;____________________________________________________________________
DEC_INC PROC
;The procedure XOR the byte from address msg CX times .
;CX must > 00H
;The procedure uses BX as an offset
PUSH CX
LEA BX,MSG
START2:
MOV AH,CODE_VAL ;moves the code value into AH
XOR [BX],AH ;XOR with offset BX
INC BX
LOOP START2
POP CX
RET ;return
DEC_INC ENDP
END MAIN ;start the program control from MAIN procedure